|
|
|
|
|
|
|
The steps for compiling an ActiveX control project are similar to those for compiling a Standard EXE project. However, the end result of compiling an ActiveX control project is an OCX file rather than an EXE program file. |
|
|
|
|
|
|
|
|
To create an OCX file for the Address control, perform the following steps: |
|
|
|
|
|
|
|
|
1. Choose Make from Visual Basic's File menu. |
|
|
|
|
|
|
|
|
2. When the Make Project dialog box appears, enter a filename, such as ADDRESS.OCX. (You might also need to set the directory where you want the file saved.) |
|
|
|
|
|
|
|
|
3. Click OK. Visual Basic compiles the control and writes the OCX file to disk. |
|
|
|
|
|
|
|
|
After the ActiveX control is compiled, you should be able to test the compiled control. Keep in mind that an ActiveX control is different from a Standard EXE application in that it does not run on its own. To test your compiled control, you need to use a container application. |
|
|
|
|
|
|
|
|
Testing the Compiled Control |
|
|
|
|
|
|
|
|
After you compile your control, it should work just like any other control. Start a new Standard EXE project in Visual Basic, removing the loaded project or project group. Next, display the Components dialog box by pressing Ctrl+T or choosing Project, Components. Click the Browse button, and select your OCX file. When you close the Components dialog box, a new icon should appear in the Toolbox. You should then be able to draw your control on the form as you did earlier when testing with a project group; this time, however, you can use compiled code. (See the earlier section "Setting Up the Test Project.") |
|
|
|
|
|
|
|
|
|
When working with a compiled control in Visual Basic, you cannot debug within the control or view its code.  |
|
|
|
|
|
|
|
|
|
|
Distributing the Control to Another Machine |
|
|
|
|
|
|
|
|
Your ActiveX controls can run on another user's or developer's PC. However, just copying the OCX file to the other computer is not a sufficient way to distribute it. For your control to run on any given PC, the appropriate support files must be installed. The reason for this requirement is that Visual Basic code is a fairly high-level language and thus depends on other runtime libraries (that is, DLL files). For example, one of the most basic requirements to run any Visual Basic program is the file MSVBVM60.DLL (Microsoft Visual Basic Virtual Machine 6.0). Without this file, none of your Visual Basic programs can run. |
|
|
|
|
|
|
|
|
|
Other users who already have Visual Basic (and the support files) installed on their machines may be able to use your control by simply copying your file to their machines and registering it with the REGSVR32 command, as in the following example: |
|
|
|
|
|
|
|
|
REGSVR32 C:\WINDOWS\SYSTEM\ADDRESS.OCX  |
|
|
|
|
|
|
|